# 使用 requests 发送请求，使用 BeautifulSoup 库进行 html 和 xml 文档的解析
import os

## Allow multiple copies of the OpenMP library
os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'
import requests
from bs4 import BeautifulSoup

url = "https://www.baidu.com/index.htm"
responses = requests.get(url)
responses.encoding = responses.apparent_encoding
if responses.status_code == 200:
    soup = BeautifulSoup(responses.text, "html.parser")
    title = soup.title.string
    print('网页标题', title)
else:
    print("请求失败，状态码：", responses.status_code)


# 使用Selenium 库可以模拟浏览器行为
from selenium import webdriver
import time

url = "https:/www.baidu.com/index.html"
driver = webdriver.Chrome()
driver.get(url)

time.sleep(5)

soup = BeautifulSoup(driver.page_source, "html.parser")
title = soup.title.string
print("网页标题", title)
driver.quit()